Skip to content

export: erwin XML that opens in real erwin (numeric dialect + --template clone) - #65

Merged
dbose merged 4 commits into
mainfrom
fix-erwin-export-dialect
Nov 3, 2026
Merged

dbose merged 4 commits into
mainfrom
fix-erwin-export-dialect

Conversation

@dbose

@dbose dbose commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Two commits on the XML-export path to erwin Data Modeler 10.10. The first fixes the per-object dialect; the second is the one that actually gets a file to open in real erwin without freezing — clone a native export as a template and inject the model into it.

1. e693e0d — numeric enum dialect

erwin 10.10 writes enums as NUMERIC codes, not words. Emitting the word forms (Non_Identifying, Zero_One_or_More) hung erwin's import engine (EAT). Now emits the codes; the importer reads both, so round-trips hold.

  • Entity Type 1, Attribute Type 0/100, Null_Option_Type 0/1, Relationship Type 2/7, Cardinality -3/-1, Key_Group_Type PK/AK1/IF1, FileVersion 10.10.38485.
  • A scoped export drops cross-SA FKs (no stub — erwin chokes on a thin stub).

2. 516381f — --template: clone a native export so the file opens in erwin

The self-built envelope (empty ModelProps, invented domains) opens as an empty Model_1 and freezes erwin at 100% CPU. The reliable path, proven against real erwin, is to clone a native export of the target mart as a template, strip its content, and inject Modelith's entities into that envelope.

emit_erwin(model, template=<path|bytes>) delegates to a new erwin_template module that ports the erwin-verified reference tool (tools/ddl_to_erwin_xml.py), driven by Modelith's IR instead of a parsed DDL script:

  • Clone the envelope (ModelProps, Domain_Groups, themes, images, page setup); strip Entity/Relationship/Subject_Area/Diagram groups + Model_Proxy_Object; remint model id/name/Locator/Persistence_Unit; drop dangling *_Refs.
  • Domains by name from the template (Number/String/d_date/d_bit), not invented BOOLEAN/BIGINT.
  • Entity Type 6 when it has an identifying parent.
  • Inferred PKs (role: business_key) emitted as explicit XPK key groups.
  • Full FK structure: parent Key_Group_Ref, child IFn key group with Relationship_Ref + Parent_Key_Group_Member_Ref, FK attrs' Parent_Attribute_Ref + Parent_Relationship_Ref, Attributes_Order_Ref_Array.
  • Relationship Null_Option_Type 101/100.
  • Scoped export keeps within-area FKs, drops cross-area (no stub). Preserved erwin_id re-emitted verbatim (erwin updates, not duplicates).

Surfaces

  • CLI: mdl export erwin --template <mart.xml> [--name] (-t).
  • API: POST /api/export/erwin multipart — the 7–10 MB template can't ride a query param; the GET route still serves the self-built envelope.
  • Canvas: Export menu adds "erwin XML (erwin-ready) — pick mart…" — a file picker that POSTs the template and downloads the result, honouring the active subject-area filter.

Without --template, the self-built envelope is unchanged (XSD-valid, round-trips via mdl import erwin, not guaranteed to open in erwin). lxml added to emit-erd deps.

docs/modelith-erwin-xml-exporter.md captures the dialect spec; tools/ddl_to_erwin_xml.py is the verbatim erwin-verified reference (excluded from ruff).

Verified

807 tests pass (10 new template + 2 API); ruff clean on packages; canvas tsc clean + 55 vitest; canvas bundle rebuilt. Not verified against real erwin in CI (no erwin on the runner) — built to the reference tool's erwin-verified output. The real test is mdl export erwin --template <your mart.xml> → File > Open > XML in erwin 10.10.

🤖 Generated with Claude Code

3. 494e656 — remember the imported erwin file, auto-clone on export

If the model was imported from an erwin export, re-exporting reuses that file as the template with no flag and no re-picking:

  • mdl import erwin records the path it imported from in export.erwin.template_path (the path, not a committed blob; preserved across re-imports).
  • mdl export erwin resolves the template as --template <file> > remembered path (unless --no-template) > none (self-built envelope). A remembered file that has moved is reported and export falls back to self-built.
  • Canvas: the GET erwin export auto-clones it; /api/export reports erwinTemplateRemembered, so the plain erwin XML item shows · erwin-ready and the picker relabels to clone a different mart….

Verified end to end: import sample.erwin.xml → mdl export erwin logs cloning remembered erwin template and the output carries the template envelope.

dbose added 2 commits November 3, 2026 10:30
…-SA stubs)

The id-format fix (0.8.4) was necessary but not sufficient: a semantic diff against a real
erwin 10.10 export that erwin imports cleanly showed our exporter writes a DIFFERENT dialect,
and real erwin's import engine (EAT) still hung. Match the dialect erwin actually reads:

- Numeric enum codes instead of words (decoded from a real erwin 10.10 export; the published
  XSD types these as free strings and does not carry the codes):
    Relationship_Type  2 identifying / 7 non-identifying   (was Identifying/Non_Identifying)
    Cardinality        -3 zero-one-or-more / -1 one         (was Zero_One_or_More/One)
    Null_Option_Type   0 null / 1 not null                  (was NULL/NOT_NULL)
    Attribute Type     0 pk-member / 100 other              (new)
    Entity Type        1                                    (new)
    Key_Group_Type     PK / AKn / IFn                       (was Primary_Key/Alternate_Key/...)
- FileVersion 10.10.38485 (was 9.8.0000). Real erwin writes and imports the 10.10 form; the
  published XSD pattern is stricter than erwin's own output and rejects it, so the XSD tests now
  validate STRUCTURE against a schema-acceptable FileVersion. A real erwin import, not the XSD,
  is the compatibility oracle.
- Scoped export: keep FKs WITHIN the subject area, DROP cross-area FKs instead of emitting a
  thin stub entity (erwin chokes on stubs). Cross-area FKs are re-established in erwin after the
  slice imports. Removes _emit_entity_stub.

The mdl_reverse importer now reads both the numeric codes and the old word forms, so round-trips
hold. Also hardens the word-form identifying read (the old 'identifying' in rtype matched
'non_identifying' too). Full suite: 1038 passed.

NOT YET VERIFIED against real erwin (no erwin in CI); built to the dialect observed in a real
10.10 export. The identifying-flag importer loss (erwin Type=2 dropped on import) is a separate
known bug, deferred.
… in real erwin

The self-built envelope (empty ModelProps, invented domains) opens in erwin DM
10.10 as an empty Model_1 and freezes the import engine at 100% CPU. The reliable
path, proven against real erwin, is to CLONE a native export of the target mart as
a template, strip its content, and inject Modelith's entities into that envelope.

emit_erwin(model, template=<path|bytes>) delegates to a new erwin_template module
that ports the erwin-verified reference tool (tools/ddl_to_erwin_xml.py), driven by
Modelith's IR instead of a parsed DDL script:

  - clone the envelope (ModelProps, Domain_Groups, themes, images, page setup);
    strip Entity/Relationship/Subject_Area/Diagram groups + Model_Proxy_Object;
    remint the model id/name/Locator/Persistence_Unit; drop dangling *_Refs
  - resolve domains BY NAME from the template (Number/String/d_date/d_bit), not
    invented BOOLEAN/BIGINT
  - entity Type 1/6 (dependent when it has an identifying parent)
  - emit inferred PKs (role: business_key) as explicit XPK key groups
  - full FK structure: parent Key_Group_Ref, child IFn key group with
    Relationship_Ref + Parent_Key_Group_Member_Ref, FK attrs' Parent_Attribute_Ref
    + Parent_Relationship_Ref, Attributes_Order_Ref_Array
  - relationship Null_Option_Type 101/100, Cardinality -1/-3, numeric Type 2/7
  - a scoped export keeps within-area FKs and drops cross-area FKs (no stub)
  - a preserved erwin_id is re-emitted verbatim so erwin UPDATES, not duplicates

Surfaces:
  - CLI: mdl export erwin --template <mart.xml> [--name] (-t)
  - API: POST /api/export/erwin multipart (the 7-10 MB template can't ride a query
    param); the GET route still serves the self-built envelope
  - canvas: Export menu "erwin XML (erwin-ready) - pick mart..." file picker that
    POSTs the template and downloads the result, honouring the subject-area filter

Without --template the self-built envelope is unchanged (XSD-valid, round-trips via
mdl import erwin, not guaranteed to open in erwin). lxml added to emit-erd deps.

docs/modelith-erwin-xml-exporter.md captures the dialect spec; tools/ (the verbatim
reference script) is excluded from ruff. 807 tests pass; canvas tsc + 55 vitest pass.
@dbose dbose changed the title export: write the erwin 10.10 dialect (numeric enum codes, drop cross-SA stubs) export: erwin XML that opens in real erwin (numeric dialect + --template clone) Nov 3, 2026
dbose added 2 commits November 3, 2026 14:23
# Conflicts:
#	packages/server/src/mdl_server/static/assets/ModelDiagram-B8BNKKus.js
#	packages/server/src/mdl_server/static/assets/ModelDiagram-B9WAgAKw.js
#	packages/server/src/mdl_server/static/assets/ModelDiagram-yDpS9fVd.js
#	packages/server/src/mdl_server/static/assets/main-CBJYBl0L.js
#	packages/server/src/mdl_server/static/assets/main-DzkzbaZK.js
#	packages/server/src/mdl_server/static/assets/main-W1aXYKPl.js
#	packages/server/src/mdl_server/static/assets/sme-C-aE5Tdu.js
#	packages/server/src/mdl_server/static/assets/sme-CoLqAg47.js
#	packages/server/src/mdl_server/static/assets/sme-N0VgjHK_.js
#	packages/server/src/mdl_server/static/assets/styles-Cw-0u507.js
#	packages/server/src/mdl_server/static/index.html
#	packages/server/src/mdl_server/static/sme.html
…plate

If you imported from an erwin export, re-exporting to erwin should reuse that
file as the template without re-picking it. `mdl import erwin` now records the
path it imported from in export.erwin.template_path (the PATH, not a committed
blob), and the erwin export resolves it automatically.

  - ErwinExportConfig gains template_path; added to the writer's _USER_OWNED_CONFIG
    so a re-import preserves it rather than wiping it
  - CLI import stamps template_path (relative to the model root when the file lives
    under it, else absolute)
  - mdl export erwin resolves the template as: --template <file> > the remembered
    path (unless --no-template) > none (self-built envelope). A remembered file that
    has moved is reported and export falls back to the self-built envelope
  - GET /api/export/erwin auto-clones the remembered template; /api/export reports
    erwinTemplateRemembered so the canvas Export menu shows the plain "erwin XML"
    item as "erwin-ready" and relabels the picker to "clone a different mart..."

End to end: import sample.erwin.xml -> export erwin re-clones it (output carries the
template's envelope), verified. 814 tests pass (8 new), ruff clean; canvas tsc + 55
vitest pass, bundle rebuilt.
@dbose
dbose merged commit 3a2eb04 into main Nov 3, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant